package com.amizah.tooling.databases.jdbc.teradata;

/**
 *@author Zaheer Abzal
 *@version 1.0.0 
 *<p><b>Description:</b>Used to pass parameters to TeradataHandler class to access a Teradata database using a
 * JDBC connection.Value Object used to pass defined parameters to TeradataHandler Class.</p> 
 *<p><b>External Dependents:</b> none </p>
 *<p><b>Date Created:</b> 2/21/2011 </p>
 *<p><b>Last Updated:</b> 2/22/2011 </p>
 */

public class TeradataParams {
	
	private String jdbcType = "jdbc:teradata:";
	private String url;
	private String tmode;
	private String charset;
	public String username;
	public String password;
	
	public TeradataParams(String xUrl,String xTmode,String xCharset,String xUser, String xPass)
	{
			
		tmode = "TMODE=" + xTmode;
		charset = "CHARSET=" + xCharset;
		
		//Construct URL
		constructURL(xUrl);
		
		username = xUser;
		password = xPass;
	}
	
	public TeradataParams(String xJdbcType, String xUrl,String xTmode,String xCharset,String xUser, String xPass)
	{
		jdbcType = xJdbcType;
		
		tmode = "TMODE=" + xTmode;
		charset = "CHARSET=" + xCharset;
		
		//Construct URL
		constructURL(xUrl);
		
		username = xUser;
		password = xPass;
	}
	
	public TeradataParams(String xUrl,String xUser, String xPass)
	{
		
		tmode = "TMODE=ANSI";
		charset = "CHARSET=UTF8";
		
		//Construct URL
		constructURL(xUrl);
		
		username = xUser;
		password = xPass;
	}
	
	/**
	 * 
	 * @return Returns URL as String Type.
	 */
	public String getURL()
	{
		return url;
	}
	
	/**
	 * @param xUrl
	 * @param xTmode
	 * @param xCharset
	 * <p><b>Notes: </b> User provides all parts of URL String for database connection.</p>
	 */
	public void setURL(String xUrl,String xTmode,String xCharset)
	{
		tmode = "TMODE=" + xTmode;
		charset = "CHARSET=" + xCharset;
		
		//Construct URL
		constructURL(xUrl);
	}
	
	/**
	 * @param xUrl
	 * <p><b>Notes: </b> User only provide base of the URL string such as IP address. Default values
	 * are used to construct the balance of the string. The getURL()method can be used to see 
	 * the entire string after construction.</p>
	 */
	public void setURL(String xUrl)
	{
		tmode = "TMODE=ANSI";
		charset = "CHARSET=UTF8";
		
		//Construct URL
		constructURL(xUrl);
	}

	public String getJDBCType()
	{
		return jdbcType;
	}
	
	/**
	 * @param xJdbcType should be of format e.g. "jdbc:teradata:"
	 */
	public void setJDBCType(String xJdbcType)
	{
		jdbcType = xJdbcType;
	}
	
	private void constructURL(String xUrl)
	{
		url = jdbcType + "//" + xUrl + "/" + tmode + "," + charset;
	}

}
